package com.shujia.connctionpoolcheck;

import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.Date;

public class PoolElem {
    // 这是Connection的包装类

    private Connection connection;

    // 创建时间
    private Date date;

    public Connection getConnection() {
        return connection;
    }

    public Date getDate() {
        return date;
    }

    public PoolElem(Connection connection, Date date) {
        this.connection = connection;
        this.date = date;
    }

    public void resetStartDate(){
        // 尽量避免用新的对象 覆盖原先的遍历  这样会导致堆内存中有大量的 无引用的对象，导致垃圾回收频繁内存使用率不高
        // this.date = new Date();


        this.date.setTime(System.currentTimeMillis());
    }

    @Override
    public String toString() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        return "PoolElem{" +
                "connection=" + connection +
                ", date=" + simpleDateFormat.format(date) +
                '}';
    }
}
